/*************************************************************************
    > File Name    : MutexLock.cc
    > Author       : LiuLei
    > Mail         : 2261459486@qq.com 
    > Created Time : 2022年11月24日 星期四 20时09分49秒
 ************************************************************************/

#include "../../include/server/MutexLock.h"
#include <stdio.h>

MutexLock::MutexLock()
: _mutex()
{
    int ret = ::pthread_mutex_init(&_mutex, nullptr);
    if(ret)
    {
        ::perror("pthread_mutex_init in MutexLock::MutexLock()");
        return ;
    }
}

MutexLock::~MutexLock()
{
    int ret = ::pthread_mutex_destroy(&_mutex);
    if(ret)
    {
        ::perror("pthread_mutex_destroy in MutexLock::~MutexLock()");
        return ;
    }
}

void MutexLock::lock()
{
    int ret = ::pthread_mutex_lock(&_mutex);
    if(ret)
    {
        ::perror("pthread_mutex_lock in MutexLock::lock()");
    }
}

void MutexLock::unlock()
{
    int ret = pthread_mutex_unlock(&_mutex);
    if(ret)
    {
        ::perror("pthread_mutex_unlock in MutexLock::unlock()");
    }
}

pthread_mutex_t *MutexLock::getMutexPtr()
{
    return &_mutex;
}
